<template>
	<view class="left-nav bg-white ht-auto" style="height: 100%;">
		<scroll-view :scroll-y="true"  class="goods-list" :scroll-top="scroll_top" @scroll="scroll_event" @scrolltolower="scroll_lower" lower-threshold="60">
			<view  v-for="(item,index) in dataList" :key="index" >
				<tui-list-cell :hover="true" :lineLeft="true" style="margin: 2px;">
					<view>
						<view class="tui-goods-title">
							<view>
								<span style="color: #888888">城市:</span>
								<span>{{item.address}}</span>
							</view>
						</view>

						<view class="tui-goods-title">
							<view>
							  <span style="color: #888888">客户名称:</span>
							  <span>{{item.customer}}</span>
							</view>
						</view>

						<view class="tui-goods-title2">
							<span style="color: #888888;padding-right: 4px;">拜访时间:</span>
							{{item.billDate}}
						</view>
						
						<view class="tui-goods-title" v-if="item.remark">
							<view>
							  <span style="color: #888888">备注:</span>
							  <span >{{item.remark}}</span>
							</view>
						</view>
						
						<view style="border-bottom: 1px dashed darkgray;"></view>
					</view>
				</tui-list-cell>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				user: null,
				dataList:[],
				pullUpOn:"",
				data_list_loding_status: 1,
				data_bottom_line_status: false,
				data_is_loading: 0,
				data_list: [],
				data_total: 0,
				data_page_total: 0,
				data_page: 1,
				load_status: 0,
				scroll_top: 0,
				scroll_top_old: 0,
			}
		},
		onShow() {
			this.user =app.globalData.get_user_info(this, 'init');
		    // 数据加载
		    this.init();
		    
		},
		
		// 下拉刷新
		onPullDownRefresh() {
		    this.setData({
		        data_page: 1
		    });
		    this.get_data_list(1);
		},
		methods: {
			// 滑动事件位置记录
			scroll_event(e) {
				//console.log("---scroll_event--",e.detail.scrollTop);
			    this.setData({
			        scroll_top_old: e.detail.scrollTop
			    });
			},
			// 滚动加载
			scroll_lower(e) {
				console.log("---scroll_lower--");
			    this.get_data_list();
			},
			add(){
				uni.navigateTo({
				    url: '/pages/sal/add-crm-visit'
				});
			},
			// 获取数据
			init() {
			    if (this.user != false) {
			        // 获取数据
			        this.get_data_list();
			    } else {
			        this.setData({
			            data_list_loding_status: 0,
			            data_bottom_line_status: false
			        });
			    }
			},
			// 获取数据
			get_data_list(is_mandatory) {
			    // 分页是否还有数据
			    if ((is_mandatory || 0) == 0) {
			        if (this.data_bottom_line_status == true) {
			            uni.stopPullDownRefresh();
			            return false;
			        }
			    }
			    
			    // 是否加载中
			    if(this.data_is_loading == 1) {
			        return false;
			    }
			    this.setData({
			        data_is_loading: 1,
			        data_list_loding_status: 1,
			    });
			    
			    // 加载loding
			    uni.showLoading({
			        title: '加载中...'
			    });
			    
			    // 参数

			    // 获取数据
			    uni.request({
			        url: app.globalData.get_request_url("crmVistitList?pageNo="+this.data_page),
			        method: 'POST',
			        data: {
			            page: this.data_page,
			            is_more: 1,
						userIdentity: this.user.userIdentity,
						roleId: this.user.role.id,
			        },
					header:{
						'Tenant-Id':this.user.role.tenantId,
						'X-Access-Token':this.user.token,
					},
			        dataType: 'json',
			        success: res => {
			            uni.hideLoading();
			            uni.stopPullDownRefresh();
						console.log("res",res);
						var temp_data_list =[];
			            if (res.data.code == 0) {
							if (this.data_page <= 1) {
							    temp_data_list = res.data.data.data;
							} else {
							    temp_data_list = this.data_list || [];
							    var temp_data = res.data.data.data;
							    for (var i in temp_data) {
							        temp_data_list.push(temp_data[i]);
							    }
							}
			            }
						
						this.dataList =temp_data_list;


						console.log("--res--",res);
						this.setData({
						    data_total: res.data.data.total,
						    data_page_total: res.data.data.page_total,
						    data_list_loding_status: 3,
						    data_page: this.data_page + 1,
						    load_status: 1,
						    data_is_loading: 0
						});
						
			        },
			        fail: () => {
			            uni.hideLoading();
			            uni.stopPullDownRefresh();
			            this.setData({
			                data_list_loding_status: 2,
			                load_status: 1,
			                data_is_loading: 0
			            });
			            app.globalData.showToast('服务器请求出错');
			        }
			    });
			},
			
			detail(e) {
				let parmas={
					is:e.id
				}
				this.$Router.push({name: 'salpricedetail',params:parmas})
			},
		}
	}
</script>

<style>
	.tui-goods-title {
		width: 100%;
		font-size: 24rpx;
    padding: 2px;
	margin: 2px 8px;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

  .tui-goods-title2 {
    width: 100%;
    padding: 2px;
	margin:2px 8px;
    font-size: 24rpx;
    display: flex;
    align-items: center;
  }

	.tui-order-status {
		color: #888;
		font-size: 26rpx;
	}
	
	.goods-list{
		height: 100vh;
		white-space: nowrap;
		display: inline-block;
	}
	
</style>
